package com.example.NearByLocation;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;

import java.util.List;

/**
 * Created by lenovo on 2014/11/24.
 */
public class ListAdapter extends BaseAdapter {
    private List<String> list;
    private int resource;
    private Context context;
    private LayoutInflater inflater;
    private TextView classify_TextView;
    private Button classify_Button;

    public ListAdapter(List<String> list, int resource, Context context) {
        this.list = list;
        this.resource = resource;
        this.context = context;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
       final String currentString = (String) getItem(position);
        View view;
        if (convertView == null) {
            inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
            view = inflater.inflate(resource,null);
        }else {
            view = convertView;
        }
        classify_TextView = (TextView) view.findViewById(R.id.classify_TextView);
        classify_TextView.setText(currentString);
        classify_Button = (Button) view.findViewById(R.id.classify_Button);
        return view;
    }
}
